<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Reads through a whole directory</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.eio-readahead.html">« eio_readahead</a></li>
      <li style="float: right;"><a href="function.eio-readlink.html">eio_readlink »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.eio.html">Eio 函数</a></li>
    <li>Reads through a whole directory</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.eio-readdir" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">eio_readdir</h1>
  <p class="verinfo">(PECL eio &gt;= 0.0.1dev)</p><p class="refpurpose"><span class="refname">eio_readdir</span> &mdash; <span class="dc-title">Reads through a whole directory</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.eio-readdir-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>eio_readdir</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$path</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$pri</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code><span class="initializer"> = NULL</span></span><br>): <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   Reads through a whole directory(via the <code class="literal">opendir</code>, <code class="literal">readdir</code> and
   <code class="literal">closedir</code> system calls) and returns either the names or an array in
   <code class="parameter">result</code> argument of <code class="parameter">callback</code>
   function, depending on the <code class="parameter">flags</code> argument.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.eio-readdir-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">path</code></dt>

    <dd>

     <p class="para">
      Directory path.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">flags</code></dt>

    <dd>

     <p class="para">
      Combination of <em class="emphasis">EIO_READDIR_*</em> constants.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">pri</code></dt>

    <dd>

     <p class="para">请求的优先级：<strong><code>EIO_PRI_DEFAULT</code></strong>，<strong><code>EIO_PRI_MIN</code></strong>，<strong><code>EIO_PRI_MAX</code></strong> 或 <strong><code>null</code></strong>。如果是
<strong><code>null</code></strong>，<code class="parameter">pri</code> 将设为
<strong><code>EIO_PRI_DEFAULT</code></strong>。
</p>

    </dd>

   
   
    <dt>
<code class="parameter">callback</code></dt>

    <dd>

      <p class="para">
<code class="parameter">callback</code>
函数在请求完成时被调用。其应匹配一下原型：<div class="example-contents"><div class="phpcode"><code><span style="color: #000000">
void&nbsp;callback(mixed&nbsp;$data,&nbsp;int&nbsp;$result[,&nbsp;resource&nbsp;$req]);</span>
</code></div></div>

<dl>
 
  <dt>
<code class="parameter">data</code></dt>

  <dd>
<p class="para">传递给请求的用户数据。</p></dd>

 
 
  <dt>
<code class="parameter">result</code></dt>

  <dd>
<p class="para">针对请求的结果的值。通常是相应的系统调用返回的值。</p></dd>

 
 
  <dt>
<code class="parameter">req</code></dt>

  <dd>
<p class="para">可选的请求资源，可被 <span class="function"><a href="function.eio-get-last-error.html" class="function">eio_get_last_error()</a></span>
   之类的函数使用。</p></dd>

 
</dl>

</p>

    </dd>

   
   
    <dt>
<code class="parameter">data</code></dt>

    <dd>

     <p class="para">
      Arbitrary variable passed to <code class="parameter">callback</code>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.eio-readdir-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>eio_readdir()</strong></span> returns request resource on success, 或者在失败时返回 <strong><code>false</code></strong>. 
   Sets <code class="parameter">result</code> argument of
   <code class="parameter">callback</code> function according to
   <code class="parameter">flags</code>:
  </p>

  <p class="para">
   <dl>

    
    
     <dt>

      <strong><code>EIO_READDIR_DENTS</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
       <span class="function"><strong>eio_readdir()</strong></span> flag. If specified, the result argument of the callback
       becomes an array with the following keys:
       <code class="literal">&#039;names&#039;</code> - array of directory names
       <code class="literal">&#039;dents&#039;</code> - array of <code class="literal">struct
       eio_dirent</code>-like arrays having the following keys each:
       <code class="literal">&#039;name&#039;</code> - the directory name;
       <code class="literal">&#039;type&#039;</code> - one of <em class="emphasis">EIO_DT_*</em>
       constants;
       <code class="literal">&#039;inode&#039;</code> - the inode number, if available, otherwise
       unspecified;
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_READDIR_DIRS_FIRST</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      When this flag is specified, the names will be returned in an order
      where likely directories come first, in optimal stat order.
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_READDIR_STAT_ORDER</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      When this flag is specified, then the names will be returned in an order
      suitable for <code class="literal">stat</code>&#039;ing each one. When planning to
      <span class="function"><a href="function.stat.html" class="function">stat()</a></span> all files in the given directory, the
      returned order will likely be
      fastest.
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_READDIR_FOUND_UNKNOWN</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">

      </span>
     </dd>

    


   </dl>

  </p>

  <p class="para">Node types:
   <dl>


    
     <dt>

      <strong><code>EIO_DT_UNKNOWN</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Unknown node type(very common). Further <span class="function"><a href="function.stat.html" class="function">stat()</a></span> needed.
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_FIFO</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      FIFO node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_CHR</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_MPC</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Multiplexed char device (v7+coherent) node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_DIR</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Directory node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_NAM</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Xenix special named file node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_BLK</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_MPB</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Multiplexed block device (v7+coherent)
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_REG</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_NWK</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_CMP</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      HP-UX network special node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_LNK</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Link node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_SOCK</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Socket node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_DOOR</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Solaris door node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_WHT</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Node type
      </span>
     </dd>

    
    
     <dt>

      <strong><code>EIO_DT_MAX</code></strong>
      (<span class="type">int</span>)
     </dt>

     <dd>

      <span class="simpara">
      Highest node type value
      </span>
     </dd>

    
 
 
 
   </dl>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.eio-readdir-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-3234">
   <p><strong>示例 #1 <span class="function"><strong>eio_readdir()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Is&nbsp;called&nbsp;when&nbsp;eio_readdir()&nbsp;finishes&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">my_readdir_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">__FUNCTION__</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;called\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"data:&nbsp;"</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"result:&nbsp;"</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">eio_readdir</span><span style="color: #007700">(</span><span style="color: #DD0000">"/var/spool/news"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">EIO_READDIR_STAT_ORDER&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">EIO_READDIR_DIRS_FIRST</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #0000BB">EIO_PRI_DEFAULT</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_readdir_callback"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">eio_event_loop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
my_readdir_callback called
data: NULL
result: array(2) {
 [&quot;names&quot;]=&gt;
  array(7) {
   [0]=&gt;
    string(7) &quot;archive&quot;
    [1]=&gt;
    string(8) &quot;articles&quot;
    [2]=&gt;
    string(8) &quot;incoming&quot;
    [3]=&gt;
    string(7) &quot;innfeed&quot;
    [4]=&gt;
    string(8) &quot;outgoing&quot;
    [5]=&gt;
    string(8) &quot;overview&quot;
    [6]=&gt;
    string(3) &quot;tmp&quot;
  }
 [&quot;dents&quot;]=&gt;
  array(7) {
   [0]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(7)
      &quot;archive&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393265)
    }
   [1]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(8)
      &quot;articles&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393266)
    }
   [2]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(8)
      &quot;incoming&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393267)
    }
   [3]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(7)
      &quot;innfeed&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393269)
    }
   [4]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(8)
      &quot;outgoing&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393270)
    }
   [5]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(8)
      &quot;overview&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393271)
    }
   [6]=&gt;
    array(3)
    {
     [&quot;name&quot;]=&gt;
      string(3)
      &quot;tmp&quot;
      [&quot;type&quot;]=&gt;
      int(4)
      [&quot;inode&quot;]=&gt;
      int(393272)
    }
  }
}
</pre></div>
   </div>
  </div>
 </div>



</div></div></div></body></html>